package com.andrew.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.andrew.entity.Customer;
import com.andrew.service.CustomerService;
import com.andrew.service.impl.CustomerServiceImpl;
import com.google.gson.Gson;

public class getAllCustomer extends HttpServlet {
	private CustomerService customerService=new CustomerServiceImpl();
	private Gson gson=new Gson();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		
		try {
			List<Customer> allCustomer = customerService.getAllCommonCustomer();
			String json=gson.toJson(allCustomer);
			resp.getWriter().write(json);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
